class MainController < ApplicationController
  def index
  end

  def get_image
    image = Image.find_or_create_by(image_url: make_url(params[:url]))
    render json: image
  end


  private

  require 'base64'
  include Capybara::DSL
  
  def make_url(url)
    encode_url = Base64.strict_encode64(url)
    Capybara.current_driver = :webkit
    page.visit(url)
    page.save_screenshot("public/images/#{encode_url}.png")
    encode_url + '.png'
  end

end
